<?php Gsm
=======
test<?php

class Gsm
>>>>>>> .r7
{
	private $model;
	private $hasSimCard;
	private $simMobileNumber;
	private $outgoingCallsDuration;
	
	private $lastIncommingCall;
	private $lastOutgoingCall;
	
	public function __construct($model)
	{
		echo "<p>Creating GSM with model $model ...</p>";
		$this->model = $model;
		$this->hasSimCard = false;
		$this->simMobileNumber = '';
		$this->outgoingCallsDuration = 0;
	}
	
	public function getModel()
	{
		return $this->model;
      echo 8;
	}
	
	public function hasSimCard()
	{
		return $this->hasSimCard;
	}
	
	public function getSimMobileNumber()
	{
		return $this->simMobileNumber;
	}
	
	public function getOutgoingCallsDuration()
	{
		return $this->outgoingCallsDuration;
	}
	
	public function clearOutgoingCallsDuration()
	{
		$this->outgoingCallsDuration = 0;
	}
	
	public function insertSimCard($simMobileNumber)
	{
		if($this->hasSimCard == true)
		{
			echo "<p>GSM already has sim card.</p>";
			return false;
		}
		
		if(!is_string($simMobileNumber))
		{
			echo "<p>Incorrect variable type.</p>";
			return false;
		}
		
		if(!(substr($simMobileNumber, 0, 2) == '08'))
		{
			echo "<p>The number does not start with 08.</p>";
			return false;
		}
		
		if(strlen($simMobileNumber) != 10)
		{
			echo "<p>The number length is not 10 digits.</p>";
			return false;
		}
		
		$this->simMobileNumber = $simMobileNumber;
		$this->hasSimCard = true;
		
		return true;
	}
	
	public function removeSimCard()
	{
		$this->simMobileNumber = '';
		$this->hasSimCard = false;
	}
	
	public function call(Gsm $reciever, $duration)
	{
		if(!is_numeric($duration))
		{
			echo '<p>Wrong type for $duration.</p>';
			return false;
		}
		
		if($duration < 0)
		{
			echo '<p>Wront value for call duration.</p>';
			return false;
		}
		
		if($this->hasSimCard == false || $reciever->hasSimCard() == false)
		{
			echo '<p>One GSM does not have sim card!</p>';
			return false;
		}
		
		if($this->simMobileNumber == $reciever->getSimMobileNumber())
		{
			echo '<p>Both numbers are the same - busy!</p>';
			return false;
		}
		
		// check references for current object $this 
		// and object of $reciever
		if($this === $reciever)
		{
			echo '<p>Both variables hold the same object!!!</p>';
			return false;
		}
		
		$this->outgoingCallsDuration += $duration;
		echo "<p>Successful call for $duration minutes.</p>";
		return true;
	}
	
	public function setLastIncommingCall(Call $lastIncommingCall)
	{
		$this->lastIncommingCall = $lastIncommingCall;
	}
	
	public function getLastIncommingCall()
	{
		return $this->lastIncommingCall;
	}
	
	public function setLastOutgoingCall(Call $lastOutgoingCall)
	{
		$this->lastOutgoingCall = $lastOutgoingCall;
	}
	
	public function getLastOutgoingCall()
	{
		return $this->lastOutgoingCall;
	}
}